﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using Castle.Components.Validator;
using System.ComponentModel;
using Castle.ActiveRecord.Queries;
namespace Mang24k99.Model.PUBC
{
    [ActiveRecord(Table = "KT_PUBC_ITEMS")]
    public partial class MKtPubcItems : ActiveRecordBase
    {
        /// <summary>
        /// Deleteses the specified where.
        /// </summary>
        /// <param name="where">The where.</param>
        public static void Deletes(string where)
        {
            DeleteAll(typeof(MKtPubcItems), where);
        }
        /// <summary>
        /// Deleteses the specified pk values.
        /// </summary>
        /// <param name="pkValues">The pk values.</param>
        public static void Deletes(System.Collections.IEnumerable pkValues)
        {
            DeleteAll(typeof(MKtPubcItems), pkValues);
        }

        /// <summary>
        /// Selects all.
        /// </summary>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectAll()
        {
            return (IList<MKtPubcItems>)FindAll(typeof(MKtPubcItems));
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectAll(params ICriterion[] criteria)
        {
            return (IList<MKtPubcItems>)FindAll(typeof(MKtPubcItems), criteria);
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectAll(Order[] orders, params ICriterion[] criteria)
        {
            return (IList<MKtPubcItems>)FindAll(typeof(MKtPubcItems), orders, criteria);
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectAll(DetachedCriteria detachedCriteria, params Order[] orders)
        {
            return (IList<MKtPubcItems>)FindAll(typeof(MKtPubcItems), detachedCriteria, orders);
        }


        /// <summary>
        /// Selects all query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static IList<MKtPubcItems> SelectAllQuery(SimpleQuery query)
        {
            return (IList<MKtPubcItems>)ExecuteQuery(query);
        }


        /// <summary>
        /// Selects the by primary key.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public static MKtPubcItems SelectByPrimaryKey(object ID)
        {
            return (MKtPubcItems)FindByPrimaryKey(typeof(MKtPubcItems), ID, false);
        }

        /// <summary>
        /// Selects the by primary key.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public static MKtPubcItems SelectOne(DetachedCriteria detachedCriteria)
        {
            return (MKtPubcItems)FindOne(typeof(MKtPubcItems), detachedCriteria);
        }
        /// <summary>
        /// Selects the one.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtPubcItems SelectOne(params ICriterion[] criteria)
        {
            return (MKtPubcItems)FindOne(typeof(MKtPubcItems), criteria);
        }

        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtPubcItems SelectFirst(params ICriterion[] criteria)
        {
            return (MKtPubcItems)FindFirst(typeof(MKtPubcItems), criteria);
        }
        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtPubcItems SelectFirst(Order[] orders, params ICriterion[] criteria)
        {
            return (MKtPubcItems)FindFirst(typeof(MKtPubcItems), orders, criteria);
        }
        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public static MKtPubcItems SelectFirst(DetachedCriteria detachedCriteria, Order[] orders)
        {
            return (MKtPubcItems)FindFirst(typeof(MKtPubcItems), detachedCriteria, orders);

        }

        /// <summary>
        /// Selects the ALL by property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectALLByProperty(string property, object value)
        {
            return (IList<MKtPubcItems>)FindAllByProperty(typeof(MKtPubcItems), property, value);
        }
        /// <summary>
        /// Selects the ALL by property.
        /// </summary>
        /// <param name="orderByColumn">The order by column.</param>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectALLByProperty(string orderByColumn, string property, object value)
        {
            return (IList<MKtPubcItems>)FindAllByProperty(typeof(MKtPubcItems), orderByColumn, property, value);
        }

        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectALLSliced(int firstResult, int maxResult, DetachedCriteria detachedCriteria)
        {
            return (IList<MKtPubcItems>)SlicedFindAll(typeof(MKtPubcItems), firstResult, maxResult, detachedCriteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectALLSliced(int firstResult, int maxResult, params ICriterion[] criteria)
        {
            return (IList<MKtPubcItems>)SlicedFindAll(typeof(MKtPubcItems), firstResult, maxResult, criteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="orders">The orders.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectALLSliced(int firstResult, int maxResult, Order[] orders, DetachedCriteria detachedCriteria)
        {
            return (IList<MKtPubcItems>)SlicedFindAll(typeof(MKtPubcItems), firstResult, maxResult, orders, detachedCriteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectALLSliced(int firstResult, int maxResult, Order[] orders, params ICriterion[] criteria)
        {
            return (IList<MKtPubcItems>)SlicedFindAll(typeof(MKtPubcItems), firstResult, maxResult, orders, criteria);
        }

        /// <summary>
        /// Countses this instance.
        /// </summary>
        /// <returns></returns>
        public static int Counts()
        {
            return Count(typeof(MKtPubcItems));
        }
        /// <summary>
        /// Countses the specified detached criteria.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static int Counts(DetachedCriteria detachedCriteria)
        {
            return Count(typeof(MKtPubcItems), detachedCriteria);
        }
        /// <summary>
        /// Countses the specified criteria.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static int Counts(params ICriterion[] criteria)
        {
            return Count(typeof(MKtPubcItems), criteria);
        }


        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static bool Exist(object id)
        {
            return Exists(typeof(MKtPubcItems), id);
        }
        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static bool Exist(DetachedCriteria detachedCriteria)
        {
            return Exists(typeof(MKtPubcItems), detachedCriteria);
        }
        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static bool Exist(params ICriterion[] criteria)
        {
            return Exists(typeof(MKtPubcItems), criteria);
        }
        protected override void OnDelete()
        {
            DeleteTime = DateTime.Now;
            MKtPubcItemsHistory mHistory = new MKtPubcItemsHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.CycNO = MKtPubcCyc.CycNO;
            mHistory.BoardNO = MKtPubcProduct.BoardNO;
            mHistory.Create();
            base.OnDelete();
        }

        /// <summary>
        /// 返回最大的调查表条目编号
        /// </summary>
        /// <returns></returns>
        public static int GetMaxCycItemsNO()
        {
            MKtPubcItems item = new MKtPubcItems();
            string Hql = @"select max(item.ItemNO) from  MKtPubcItems item  ";
            string count = @"select count(item.ItemNO) from  MKtPubcItems item ";
            ScalarQuery querycount = new ScalarQuery(typeof(MKtPubcItems), count);
            if (Convert.ToInt32(ExecuteQuery(querycount)) == 0)
            {
                return 0;
            }
            ScalarQuery query = new ScalarQuery(typeof(MKtPubcItems), Hql);
            return (int)ExecuteQuery(query);
        }
        /// <summary>
        /// 根据where条件查询记录
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectByWhere(string where)
        {
            string hql = @" from MKtPubcItems item "+where;
            SimpleQuery query = new SimpleQuery(typeof(MKtPubcItems),hql);
            return (IList<MKtPubcItems>)ExecuteQuery(query);
        }
        [BelongsTo("CYC_NO", Cascade = CascadeEnum.None)]
        public MKtPubcCyc MKtPubcCyc
        {
            get
            {
                return _MKtPubcCyc;
            }
            set
            {
                _MKtPubcCyc = value;
            }
        }
        [BelongsTo("BOARD_NO", Cascade = CascadeEnum.None)]
        public MKtPubcProduct MKtPubcProduct
        {
            get
            {
                return _MKtPubcProduct;
            }
            set
            {
                _MKtPubcProduct = value;
            }
        }

        [HasMany(typeof(MKtPubcVote), ColumnKey = "ITEM_NO", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, Inverse = true, Lazy = true)]
        public IList<MKtPubcVote> MKtPubcVote
        {
            get
            {
                return _MKtPubcVote;
            }
            set
            {
                _MKtPubcVote = value;
            }
        }

        /// <summary>
        /// Gets or sets the ItemNO.(ItemNO)
        /// </summary>
        /// <value>The ItemNO.</value>
        /// <remarks>
        /// ItemNO
        /// </remarks>
        [PrimaryKey(PrimaryKeyType.Assigned, "ITEM_NO"),
        ValidateNonEmpty("ItemNO不能为空"),
        ValidateRange(0, 2147483647, "ItemNO的值要在0到2147483647之间"),
        ]
        public int? ItemNO
        {
            get
            {
                return _ItemNO;
            }
            set
            {
                _ItemNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the ID.(ID)
        /// </summary>
        /// <value>The ID.</value>
        /// <remarks>
        /// ID
        /// </remarks>
        [Property("ID", Insert = false, Update = false),
        ValidateNonEmpty("ID不能为空"),
        ValidateRange(0, 2147483647, "ID的值要在0到2147483647之间"),
        ]
        public int? ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }


        /// <summary>
        /// Gets or sets the ItemName.(ItemName)
        /// </summary>
        /// <value>The ItemName.</value>
        /// <remarks>
        /// ItemName
        /// </remarks>
        [Property("ITEM_NAME"),
        ValidateLength(1, 120, "ItemName长度必须在1到120之间"),
        ]
        public string ItemName
        {
            get
            {
                return _ItemName;
            }
            set
            {
                _ItemName = value;
            }
        }


        /// <summary>
        /// Gets or sets the ItemAlias.(ItemAlias)
        /// </summary>
        /// <value>The ItemAlias.</value>
        /// <remarks>
        /// ItemAlias
        /// </remarks>
        [Property("ITEM_ALIAS"),
        ValidateLength(1, 30, "ItemAlias长度必须在1到30之间"),
        ]
        public string ItemAlias
        {
            get
            {
                return _ItemAlias;
            }
            set
            {
                _ItemAlias = value;
            }
        }


        /// <summary>
        /// Gets or sets the PowerRtio.(PowerRtio)
        /// </summary>
        /// <value>The PowerRtio.</value>
        /// <remarks>
        /// PowerRtio
        /// </remarks>
        [Property("POWER_RTIO"),
        ValidateRange(0, 2147483647, "PowerRtio的值要在0到2147483647之间"),
        ]
        public int? PowerRtio
        {
            get
            {
                return _PowerRtio;
            }
            set
            {
                _PowerRtio = value;
            }
        }


        /// <summary>
        /// Gets or sets the IsValidate.(IsValidate)
        /// </summary>
        /// <value>The IsValidate.</value>
        /// <remarks>
        /// IsValidate
        /// </remarks>
        [Property("IS_VALIDATE"),
        ValidateRange(0, 2147483647, "IsValidate的值要在0到2147483647之间"),
        ]
        public int? IsValidate
        {
            get
            {
                return _IsValidate;
            }
            set
            {
                _IsValidate = value;
            }
        }


        /// <summary>
        /// Gets or sets the InputTime.(InputTime)
        /// </summary>
        /// <value>The InputTime.</value>
        /// <remarks>
        /// InputTime
        /// </remarks>
        [Property("INPUT_TIME"),
        ]
        public DateTime? InputTime
        {
            get
            {
                return _InputTime;
            }
            set
            {
                _InputTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the ModifyTime.(ModifyTime)
        /// </summary>
        /// <value>The ModifyTime.</value>
        /// <remarks>
        /// ModifyTime
        /// </remarks>
        [Property("MODIFY_TIME"),
        ]
        public DateTime? ModifyTime
        {
            get
            {
                return _ModifyTime;
            }
            set
            {
                _ModifyTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the DeleteTime.(DeleteTime)
        /// </summary>
        /// <value>The DeleteTime.</value>
        /// <remarks>
        /// DeleteTime
        /// </remarks>
        [Property("DELETE_TIME"),
        ]
        public DateTime? DeleteTime
        {
            get
            {
                return _DeleteTime;
            }
            set
            {
                _DeleteTime = value;
            }
        }



        private int? _ItemNO;

        private IList<MKtPubcVote> _MKtPubcVote;
        private int? _ID;

        private MKtPubcCyc _MKtPubcCyc;
        private MKtPubcProduct _MKtPubcProduct;
        private string _ItemName;

        private string _ItemAlias;

        private int? _PowerRtio;

        private int? _IsValidate;

        private DateTime? _InputTime;

        private DateTime? _ModifyTime;

        private DateTime? _DeleteTime;


    }
}
